﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Cms.Web.CmsSystem.SysModules.Portal
{
    public partial class WebPart : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = EntLib.Request.GetString("action");
            if (!String.IsNullOrEmpty(action) && action == "modify")
            {
                string formid = EntLib.Request.GetString("RecID");
                RecID = formid;
            }
            else
            {
                action = "add";
                RecID = System.Guid.NewGuid().ToString();
            }
            Action = action;
        }
        public string Action { get; set; }
        public string RecID { get; set; }

        private static Dictionary<string, int> _wpttype = null;
        private static object objwpt = new object();
        private static Dictionary<string, int> WptType
        {
            get {
                if (_wpttype == null)
                    lock (objwpt)
                    {
                        _wpttype = EntLib.TypeParse.GetEnumMember(typeof(Cms.Model.WebPartType));
                    }
                return _wpttype;
            }
        }
        private static Dictionary<string, int> _dtstype = null;
        private static object objdts = new object();
        private static Dictionary<string, int> DataSourceType
        {
            get
            {
                if(_dtstype ==null)
                    lock (objdts)
                    {
                        _dtstype = EntLib.TypeParse.GetEnumMember(typeof(Cms.Model.DataSouceType));
                    }
                return _dtstype;
            }
        }

        public static string JsWpttype
        {
            get {
                //StringBuilder sb = new StringBuilder();
                //foreach (KeyValuePair<string, int> k in WptType)
                //{
                //    sb.AppendFormat("{0}:{1},",k.Key,k.Value);
                //}
                //return sb.ToString().Trim(',');
                return EntLib.Json.ToJson(WptType);
            }
        }
        public static string JsDataSourcetype
        {
            get
            {
                return EntLib.Json.ToJson(DataSourceType);
            }
        }
        public static string WptOptions
        {
            get {
                StringBuilder sb = new StringBuilder();

                foreach (KeyValuePair<string, int> k in WptType)
                {
                    sb.AppendFormat("<option value='{1}'>{0}</option>", k.Key , k.Value);
                }
                return sb.ToString();
            }
        }
        public static string DtsOptions
        {
            get
            {
                StringBuilder sb = new StringBuilder();

                foreach (KeyValuePair<string, int> k in DataSourceType)
                {
                    sb.AppendFormat("<option value='{1}'>{0}</option>", k.Key, k.Value);
                }
                return sb.ToString();
            }
        }
    }
}
